package no.ntnu.fp.model1;

import java.awt.Color;
import java.util.*;

public class LWS {

	private ArrayList<Well> wellList;
	private int localWatchSystemId;
	//private int t;
	private int green;
	private int yellow;
	private int red;
	private lwsGui l;
	
	public LWS(int id){
		localWatchSystemId = id;
		wellList = new ArrayList<Well>();
		//l = new lwsGui(this);
	}
	
	private void colorCount(){
		Iterator<Well> it = this.iterator();
		green = 0; 
		yellow = 0;
		red = 0;
		while(it.hasNext()){
			Well aWell = (Well)it.next();
			Color wellColor = aWell.getCurrentColor();
			if(wellColor==Color.green){
				green++;
			}else if(wellColor==Color.yellow){
				yellow++;
			}else if(wellColor==Color.red){
				red++;
			}
		}
		l.setTextFelt(green, yellow, red);
	}
	
	public int getGreenCount() {
		colorCount();
		return green;
	}
	public int getYellowCount() {
		return yellow;
	}
	public int getRedCount() {
		return red;
	}
	
	public ArrayList<Well> getWellList(){
		return wellList;
	}
	
	public void addWell(Well well){
		wellList.add(well);
	}
	public Well getWell(int i){
		return wellList.get(i);
	}
	public int getWellCount() {
		return wellList.size();
	}
	public int indexOf(Object obj) {
		return wellList.indexOf(obj);
	}
	public void removeWell(Well well) {
		wellList.remove(well);
	}
	
	public void setLocalWatchSystemId(int localWatchSystemId) {
		this.localWatchSystemId = localWatchSystemId;
	}
	public int getLocalWatchSystemId() {
		return localWatchSystemId;
	}
	
	public Iterator<Well> iterator() {
		return wellList.iterator();
	}
	
	public boolean equals(Object o) {
		if (super.equals(o))
			return true;

		if (o.getClass() != this.getClass())
			return false;
		
		LWS aWatchSystem = (LWS)o;
		
		if (aWatchSystem.getWellCount() != getWellCount())
			return false;
		
		Iterator<Well> it = this.iterator();
		while (it.hasNext()) {
			Well aWell = (Well)it.next();
			if (aWatchSystem.indexOf(aWell) < 0)
				return false;
		}
		
		return true;
	}
	
}
